﻿using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.List.PlugIn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.Bill;
using System.ComponentModel;
using System.Net.NetworkInformation;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.App.Data;
using System.Security.Cryptography;

namespace NS
{
    [HotUpdate]
    [Description("采购订单获取电子回单")]
    public class ElectronicReceipt : AbstractListPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.Equals("WLLZ_tbButton"))
            {
                string FRELBILLNO = "",FID="";
                long pkKey = 0;
                if (this.ListView.CurrentSelectedRowInfo == null
                || !long.TryParse(this.ListView.CurrentSelectedRowInfo.PrimaryKeyValue, out pkKey)
                || pkKey <= 0)
                {
                    this.View.ShowErrMessage("没有选择任何数据，请先选择数据！");
                    return;
                }
                ListSelectedRowCollection listcoll = this.ListView.SelectedRowsInfo;
                DynamicObjectCollection dycoll = this.ListModel.GetData(listcoll);
                if (listcoll[0].EntryEntityKey != "FIinstallment")
                {
                    this.View.ShowErrMessage("请选择付款计划页签！");
                    return;
                }
                if (listcoll.Count>1)
                {
                    this.View.ShowErrMessage("请选择一行数据！");
                    return;
                }
                if(dycoll[0]["FRELBILLNO"].ToString()==""||dycoll[0]["FRELBILLNO"].ToString() == " ")
                {
                    this.View.ShowErrMessage("无电子回单！");
                    return;
                }
                FRELBILLNO = Convert.ToString(dycoll[0]["FRELBILLNO"]);
                string SQL = "/*dialect*/" + string.Format(@"select FID from T_WB_Receipt where FSRCBILLNO='{0}'", FRELBILLNO);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if(DynamData.Count>0)
                {
                    FID = Convert.ToString(DynamData[0]["FID"]);
                }
                if (FID == "" || FID == " ")
                {
                    this.View.ShowErrMessage("无电子回单！");
                    return;
                }
                BillShowParameter showParam = new BillShowParameter();
                showParam.FormId = "WB_ReceiptBill";
                showParam.PageId = Guid.NewGuid().ToString();
                showParam.ParentPageId = this.View.PageId;
                showParam.PKey = FID;
                showParam.OpenStyle.ShowType = ShowType.Modal;//浮动
                showParam.Status = OperationStatus.EDIT;
                //showParam.OpenStyle.TagetKey = this.Context.ClientType == Kingdee.BOS.ClientType.Html ? "btnCustomizeMenu" : "menuRightBtn";//浮动在menuRightBtn上,如果是H5浮动在齿轮图标上
                showParam.Width = 800;
                this.View.ShowForm(showParam);
            }
        }
    }
    [Description("费用报销单获取电子回单")]
    public class ER_ExpReimbursement : AbstractListPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.Equals("WLLZ_tbButton"))
            {
                string FRELBILLNO = "", FID = "";
                long pkKey = 0;
                if (this.ListView.CurrentSelectedRowInfo == null
                || !long.TryParse(this.ListView.CurrentSelectedRowInfo.PrimaryKeyValue, out pkKey)
                || pkKey <= 0)
                {
                    this.View.ShowErrMessage("没有选择任何数据，请先选择数据！");
                    return;
                }
                ListSelectedRowCollection listcoll = this.ListView.SelectedRowsInfo;
                DynamicObjectCollection dycoll = this.ListModel.GetData(listcoll);
                if (listcoll[0].EntryEntityKey != "FEntity")
                {
                    this.View.ShowErrMessage("请选择费用报销明细！");
                    return;
                }
                if (listcoll.Count > 1)
                {
                    this.View.ShowErrMessage("请选择一行数据！");
                    return;
                }
                if (dycoll[0]["F_WNEG_Text"].ToString() == "" || dycoll[0]["F_WNEG_Text"].ToString() == " ")
                {
                    this.View.ShowErrMessage("无电子回单！");
                    return;
                }
                FRELBILLNO = Convert.ToString(dycoll[0]["F_WNEG_Text"]);
                string SQL = "/*dialect*/" + string.Format(@"select FID from T_WB_Receipt where FSRCBILLNO='{0}'", FRELBILLNO);
                DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
                if (DynamData.Count > 0)
                {
                    FID = Convert.ToString(DynamData[0]["FID"]);
                }
                if (FID == "" || FID == " ")
                {
                    this.View.ShowErrMessage("无电子回单！");
                    return;
                }
                BillShowParameter showParam = new BillShowParameter();
                showParam.FormId = "WB_ReceiptBill";
                showParam.PageId = Guid.NewGuid().ToString();
                showParam.ParentPageId = this.View.PageId;
                showParam.PKey = FID;
                showParam.OpenStyle.ShowType = ShowType.Modal;//浮动
                showParam.Status = OperationStatus.EDIT;
                //showParam.OpenStyle.TagetKey = this.Context.ClientType == Kingdee.BOS.ClientType.Html ? "btnCustomizeMenu" : "menuRightBtn";//浮动在menuRightBtn上,如果是H5浮动在齿轮图标上
                showParam.Width = 800;
                this.View.ShowForm(showParam);
            }
        }
    }
}
